package ace.cmp.spring.util.autoconfig;

import ace.cmp.spring.util.core.SpringUtils;
import ace.cmp.spring.util.core.ValidatorUtils;
import jakarta.validation.Validator;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author caspar
 * @date 2023/9/20 9:27
 */
@Configuration
public class SpringUtilsAutoConfig {
  @ConditionalOnMissingBean
  @Bean
  public SpringUtils springUtils() {
    return new SpringUtils();
  }

  @ConditionalOnMissingBean
  @Bean
  public ValidatorUtils validatorUtils(ObjectProvider<Validator> validatorObjectProvider) {
    return new ValidatorUtils(validatorObjectProvider.getIfAvailable());
  }
}
